#!/usr/bin/env bash

declare -A name_count
cat file_name | while read name
do
    echo "${name}"
    name_count[$name]=$((${name_count[$name]}+1))
done
##下面为空，因为上面用到了管道，赋值在subshell中
echo "key:${!name_count[*]}"
for name in ${!name_count[*]}
do
    echo "$name : ${name_count[$name]}"
done

#########

while read name
do
    echo "${name}"
    name_count[$name]=$((${name_count[$name]}+1))
done < file_name
##下面不为空
echo "key:${!name_count[*]}"
for name in ${!name_count[*]}
do
    echo "$name : ${name_count[$name]}"
done